/*
 * @Descripttion: 购物车相关控制器
 * @version: 
 * @Author: 一氧化二氢
 * @Date: 2022-01-03 21:35:47
 * @lastEditorTime: Do no edit
 */

const { addCartError } = require('../constant/err.type')
const { createOrUpdate } = require('../service/cart.service')
class CartController {
    async add(ctx) {
        const user_id = ctx.state.user.id
        const goods_id = ctx.request.body.goods_id
        try {
            const res = await createOrUpdate(user_id, goods_id)
            ctx.body = {
                code: 0,
                message: "添加商品到购物车成功",
                result: res
            }
        } catch (err) {
            console.error("添加购物车失败", err)
            ctx.app.emit("error", addCartError, ctx)
        }


    }
}
module.exports = new CartController()